﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RoketPack.Management.Objects
{
    class Detector
    {
        private string p_Value = null;
        private DetectorType p_Type = DetectorType.NONE;
        private List<Variable> p_Variables = null;

        private enum DetectorType
        {
            NONE,
            FILE,
            FOLDER
        }

        internal Detector(string value, string type)
        {
            this.p_Value = value;
            switch (type)
            {
                case "file":
                    this.p_Type = DetectorType.FILE;
                    break;
                case "folder":
                    this.p_Type = DetectorType.FOLDER;
                    break;
                default:
                    throw new InvalidOperationException();
            }
        }

        internal bool Matched()
        {
            switch (this.p_Type)
            {
                case DetectorType.FILE:
                    return (System.IO.File.Exists(PathTranslator.Parse(this.p_Value, this.p_Variables)));
                case DetectorType.FOLDER:
                    return (System.IO.Directory.Exists(PathTranslator.Parse(this.p_Value, this.p_Variables)));
                default:
                    return false;
            }
        }

        internal List<Variable> Variables
        {
            set
            {
                this.p_Variables = value;
            }
        }
    }
}
